/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2025-02-10 15:32:37
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2025-02-26 08:36:33
 * @FilePath: /vue3-admin-server/src/admin/v1/modules/auth/my.controller.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Controller, UseGuards, Get, Req } from '@nestjs/common';

import { AuthGuard } from 'src/guards/auth.guard';
import { UserService } from 'src/shareModules/auth/auth.module';
import { ResponseService } from 'src/shareModules/common/common.module';

@Controller('admin/api/v1/my')
@UseGuards(AuthGuard)
export class MyController {
    constructor(
        private readonly userService: UserService,
        private readonly responseService: ResponseService
    ) {}

    @Get('info')
    async info(
        @Req() req: HwRequest
    ): Promise<VO.ResultVO<VO.UserVO | undefined>> {
        const tokenPayload = req.tokenPayload;
        if (tokenPayload === undefined)
            return this.responseService.unauthorized(undefined);
        const userInfo = await this.userService.readDetail(tokenPayload.id);
        return this.responseService.success(undefined, userInfo ?? undefined);
    }
}
